package com.hfjyz.registration.service;

import org.springframework.validation.BindException;

import com.hfjyz.registration.command.UserPasswordResetCommand;
import com.hfjyz.registration.dao.UserDao;
import com.hfjyz.registration.model.User;
import com.hfjyz.registration.util.CryptUtil;

public class UserPasswordServiceImpl extends AbstractServiceImpl implements
		UserPasswordService {
	private UserDao userDao;

	// private ApplyDao applyDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

	// public ApplyDao getApplyDao() {
	// return applyDao;
	// }
	//
	// public void setApplyDao(ApplyDao applyDao) {
	// this.applyDao = applyDao;
	// }

    @Override
    public void searchUserApplyInfo(UserPasswordResetCommand cmd, Integer examId,
            BindException errors) throws Exception {
        User u = userDao.getByIdCardNo(cmd.getIdCardNo(), examId);
        if (u == null) {
            errors.rejectValue("idCardNo", "required.idCardNo", "身份证号不正确!");
            return;
        }
        cmd.setUser(u);
		// List<Apply> applyList = applyDao.findApplyInfo(u.getId(), cmd.getex);
		// if (applyList == null || applyList.isEmpty()) {
		// errors.rejectValue("idCardNo", "required.apply", "找不到该考生的报名信息");
		// return;
		// }
		// Apply a = applyList.get(0);
		// cmd.setApply(a);
    }

    @Override
    public void resetUserPasswor(String idCardNo, String initPassword, Integer examId)
            throws Exception {
        User u = userDao.getByIdCardNo(idCardNo, examId);
        u.setPassword(CryptUtil.encrypt(initPassword));
        userDao.update(u);
    }
}
